<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="com.lmpop.trade.ts_area.*" %>
<%@page import="com.lmpop.trade.ti_goods_ship.*" %>
<%@page import="java.util.*" %>
<%@page import="com.lmpop.frame.util.PageTools" %>
<%
	request.setCharacterEncoding("UTF-8");
	Ts_area ts_area = new Ts_area();
	Ti_goods_ship ti_goods_ship = new Ti_goods_ship();
	Ti_goods_shipInfo shipfeearea = new Ti_goods_shipInfo();
	String area_attr = "",cust_id="",goods_id="",user_id="";
	if( session.getAttribute("session_area_attr") != null ){
		area_attr = session.getAttribute("session_area_attr").toString();	
	}
	if( session.getAttribute("session_cust_id") != null ){
		cust_id = session.getAttribute("session_cust_id").toString();	
	}
	
	if( session.getAttribute("session_user_id") != null ){
		user_id = session.getAttribute("session_user_id").toString();	
	}
	if(request.getParameter("goods_id")!=null && !request.getParameter("goods_id").equals("")){
		goods_id = request.getParameter("goods_id").trim();
	}
	ti_goods_ship.setCust_id(cust_id);
	ti_goods_ship.setGoods_id(goods_id);
	
	
	String s_areaname = "",up_area_id="",back_area_id="";
	Ts_areaInfo ts_areaInfo = new Ts_areaInfo();
	if(request.getParameter("s_areaname")!=null && !request.getParameter("s_areaname").equals("")){
		s_areaname = request.getParameter("s_areaname").trim();
		ts_area.setArea_name(s_areaname);
	}
	if(request.getParameter("up_area_id")!=null && !request.getParameter("up_area_id").equals("")){
		up_area_id = request.getParameter("up_area_id");
		ts_area.setUp_area_id(up_area_id);
		if(!up_area_id.equals("000000000000000")){
		back_area_id = ts_areaInfo.getUpAreaId(up_area_id);
    }	
	}else {
		up_area_id = "000000000000000";
		ts_area.setUp_area_id(up_area_id);
	}			

	String iStart = "0";
	int limit = 20;
	if(request.getParameter("iStart")!=null) iStart = request.getParameter("iStart");
	List list = ts_areaInfo.getListByPage(ts_area,Integer.parseInt(iStart),limit);
	int counter = ts_areaInfo.getCountByObj(ts_area);
	String pageString = new PageTools().getGoogleToolsBar(counter,"areaindex.jsp?s_areaname="+s_areaname+"&up_area_id="+up_area_id+"&goods_id="+goods_id+"&iStart=",Integer.parseInt(iStart),limit);
%>
<html>
  <head>
    
    <title>运费管理</title>
	<link href="/program/company/index/css/style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="/js/commen.js"></script>
	<script type="text/javascript" src="js_goods.js"></script>
</head>

<body>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td width="90%">
				<h1>运费管理</h1>
			</td>
			<td>
				
			</td>
		</tr>
	</table>
	
	<form action="index.jsp" name="indexForm" method="post">
	
	 

	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr><td height="30" align="center" bgcolor="#ECE6E6"><%=pageString %></td></tr>
	</table>
	
	<% 
		int listsize = 0;
		if(list!=null && list.size()>0){
			listsize = list.size();
	%>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
		<tr>
			<td width="90%">
				
				<input type="button" name="sortN" onClick="goodstransfee(this)" value="设置配送费" class="buttab"/>
			</td>
			<td>
				总计:<%=counter %>条
			</td>
		</tr>
	</table>
	
	<table width="100%" cellpadding="1" cellspacing="1" class="listtab" border="0">
		<tr>
			 
			
		  	<th>区域名称</th>
		  	 
		  	<th>单位运费</th>		  	
		  	
				<th width="10%">配送范围</th>
				 
		</tr>
		
		
		<% 
		  		for(int i=0;i<list.size();i++){
		  			Hashtable map = (Hashtable)list.get(i);
		  			String area_id="",area_name="",sort_no="";
		  			  	if(map.get("area_id")!=null) area_id = map.get("area_id").toString();
						  	if(map.get("area_name")!=null) area_name = map.get("area_name").toString();
						  	if(map.get("up_area_id")!=null) up_area_id = map.get("up_area_id").toString();
						  	if(map.get("sort_no")!=null) sort_no = map.get("sort_no").toString();
								boolean existSonArea= ts_areaInfo.checkSonArea(area_id);
								ti_goods_ship.setArea_attr(area_id);	
								List existlist = shipfeearea.getListByArea(ti_goods_ship);
								 
		  %>
		
		<tr>
			 
			
		  	<td>
					<%
						if(existSonArea){
					%>
						<input type="hidden" name="existSonArea<%=i%>" value="1" id="existSonArea<%=i%>" />
						<a href="areaindex.jsp?up_area_id=<%=area_id%>&goods_id=<%=goods_id%>" title="查看下级区域">
						 <img src="/program/admin/images/1.gif" border="0" style="cursor:pointer;"/>
						 <%=area_name%>
						</a>
					<%
					}else{
					%>
					<%=area_name%>
					<%}%>		
		  	</td>
		  	
		  	
		  	<%
		  		 
		  			if (existlist != null && existlist.size()>0)
		  			{
		  				Hashtable existlistMap =(Hashtable)existlist.get(0);
		  				String ship_price = "";
		  				if(existlistMap.get("ship_price")!=null)
				  	  {
				  		 ship_price = existlistMap.get("ship_price").toString();
				  	  }
		  	%>
		  	<td><input type="text" id="<%=area_id%>" name="<%=area_id%>" value="<%=ship_price%>" size="4" maxlength="3" onblur="if(!/^[0-9]*$/.test(this.value))this.value=''"> 元</td>		  		
		  	<td><font color="blue">已开通</font></td>	
		  	<%
		  			}
		  		else
		  			{
		  	%>
		  	<td>未开通配送</td>		  	 
				<td width="10%"><a href="/doTradeReg.do?goods_id=<%=goods_id%>&cust_id=<%=cust_id%>&area_attr=<%=area_id%>&ship_price=0&publish_user_id=<%=user_id%>&bpm_id=2730&area_price_add=0&num_price_add=0&member_price=0&rsrv_str2=0&rsrv_str3=0">点击开通</a></td>
	  		<%
		  			}
		  		 
		  	%>
		</tr>
		
		  <%
		  		}
		  %>
		
	</table>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
		<tr>
			<td width="90%">
				
				<input type="button" name="sortN" onClick="goodstransfee(this)" value="设置配送费" class="buttab"/>
			</td>
			<td>
				总计:<%=counter %>条
			</td>
		</tr>
	</table>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr><td height="30" align="center" bgcolor="#ECE6E6"><%=pageString %></td></tr>
	</table>
	
	<%
		 }
	%>
<table align="center">
			<%if(!up_area_id.equals("000000000000000")){%>
			<tr >
				<td>
			     		<input type="button" class="buttoncss" name="tradeRut" value="返回" onClick="location.href='index.jsp?up_area_id=<%=back_area_id%>'" style="cursor:pointer;">			  
				</td>			
			</tr>
			<%
			//out.print(up_area_id);
			}
			%>	
</table>	
	  <input type="hidden" name="listsize" id="listsize" value="<%=listsize %>" />
	  <input type="hidden" name="up_area_id" id="up_area_id" value="<%=up_area_id %>" />
	  <input type="hidden" name="pkid" id="pkid" value="" />
	  <input type="hidden" name="sort" id="sort" value="" />
	  <input type="hidden" name="cust_id" id="cust_id" value="<%=cust_id%>" />
	  <input type="hidden" name="goods_id" id="goods_id" value="<%=goods_id%>" />
	  <input type="hidden" name="bpm_id" id="bpm_id" value="5855" />
	  </form>
</body>

</html>
